
new Vue({
    el: '#app',
    store,
    data() {
        return {
            queryObj: getQueryObject(),
            tipList: [],
            tipVisible: false,
            nowVal: 100,
            processConfig: {
                tableId: 1,
                workFlowDef: {
                    name: "",
                    type: ""
                },
                directorMaxLevel: 4,
                flowPermission: [],
                nodeConfig: {
                    nodeName: "发起人",
                    approval_config_id: "",//id
                    current_node_approver: "",//节点类型
                    care_of: "false",//允许审批人转交
                    children_node: [],//子节点id
                    group_node: [],//父节点id
                    isRoutingRoot: 0, //是否底层
                    type: 0,
                    priorityLevel: "1",
                    settype: "",
                    selectMode: "",
                    selectRange: "",
                    directorLevel: "",
                    examineMode: "",
                    noHanderAction: "",
                    examineEndDirectorLevel: "",
                    ccSelfSelectFlag: "",
                    conditionList: [],
                    nodeUserList: [],
                    childNode: {},
                    conditionNodes: []
                }
            },
            nodeConfig: {},
            workFlowDef: {},
            flowPermission: [],
            directorMaxLevel: 0,
        }
    },
    mounted() {
        const stringify = sessionStorage.getItem("approvalJSON")
        if (stringify) {
            this.processConfig = JSON.parse(stringify);
        }
        this.init();
    },
    methods: {
        init() {
            let { nodeConfig, flowPermission, directorMaxLevel, workFlowDef, tableId } = this.processConfig
            this.nodeConfig = nodeConfig;
            this.flowPermission = flowPermission;
            this.directorMaxLevel = directorMaxLevel;
            this.workFlowDef = workFlowDef
            this.$store.commit('setTableId', tableId)
        },
        toReturn() {
            window.history.go(-1)
        },
        reErr({ childNode }) {
            if (childNode) {
                let { type, error, nodeName, conditionNodes } = childNode
                if (type == 1 || type == 2) {
                    if (error) {
                        this.tipList.push({ name: nodeName, type: ["", "审核人", "抄送人"][type] })
                    }
                    this.reErr(childNode)
                } else if (type == 3) {
                    this.reErr(childNode)
                } else if (type == 4) {
                    this.reErr(childNode)
                    for (var i = 0; i < conditionNodes.length; i++) {
                        if (conditionNodes[i].error) {
                            this.tipList.push({ name: conditionNodes[i].nodeName, type: "条件" })
                        }
                        this.reErr(conditionNodes[i])
                    }
                }
            } else {
                childNode = null
            }
        },
        saveSet() {
            this.$store.commit('setIsTried', true)
            this.tipList = [];
            this.reErr(this.nodeConfig);
            if (this.tipList.length != 0) {
                this.tipVisible = true;
                return;
            }
            this.processConfig.flowPermission = this.flowPermission
            this.configCount(this.processConfig.nodeConfig)
            this.configNode(this.processConfig.nodeConfig)
            sessionStorage.setItem("approvalJSON",JSON.stringify(this.processConfig))
            window.history.go(-1);
            //接口
        },
        zoomSize(type) {
            if (type == 1) {
                if (this.nowVal == 50) return;
                this.nowVal -= 10;
            } else {
                if (this.nowVal == 300) return;
                this.nowVal += 10;
            }
        },
        configCount(node, count = '1') {
            node.approval_config_id = count;
            //判断是否在路由下的节点
            let header = '';
            if (count.includes('-')) {//判断id是带横杠
                let ids = count.split('-')
                for (let i = 0; i < ids.length - 1; i++) {
                    header = header + ids[i] + '-'
                }
                count = parseInt(ids[ids.length - 1])
            }
            if (node.type == 4) {//为路由
                for (let i = 0; i < node.conditionNodes.length; i++) {
                    let newCount = header + count + '-' + (i + 1) + '-1';//id
                    this.configCount(node.conditionNodes[i], newCount)
                }
                this.configCount(node.childNode, header + (parseInt(count) + 1))
            } else if (Object.keys(node.childNode).length > 0) {//不为路由
                this.configCount(node.childNode, header + (parseInt(count) + 1));
            } else {
                node.isRoutingRoot = 1;
            }
        },
        configNode(node, group_node = []) {
            node.group_node = group_node;
            if (node.type == 4) {//为路由
                node.children_node = []
                let new_group_node = []
                for (let i = 0; i < node.conditionNodes.length; i++) {
                    node.children_node.push(node.conditionNodes[i].approval_config_id)
                    let id = this.configNode(node.conditionNodes[i], [node.approval_config_id])
                    new_group_node.push(id);
                }
                this.configNode(node.childNode, new_group_node)
            } else if (Object.keys(node.childNode).length > 0) {
                node.children_node = [node.childNode.approval_config_id];
                return this.configNode(node.childNode, [node.approval_config_id]);
            } else {
                return node.approval_config_id
            }
        }
    }
})